package dns;

import freemap.Freemap;
import freemap.Node;
import freemap.Position;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author chris
 */
public class dnsToFreemap {

    public static void main(String args[]) {
        Freemap map = new Freemap("SHAREADM");
        try {
            for (int x = 1; x <= 10; x++) {
                InetAddress ia = InetAddress.getByName("192.168.10." + x);
                if (!ia.getCanonicalHostName().equals(ia.getHostAddress()) && ia.getCanonicalHostName() != null && ia.getHostAddress() != null) {
                    Node hostNode = new Node(ia.getHostAddress(), map.getId());
                    hostNode.setPosition(Position.LEFT);
                    hostNode.setFolded(false);
                    Node child = new Node(ia.getCanonicalHostName(), map.getId());
                    List<Node> children = new ArrayList<Node>();
                    children.add(child);
                    hostNode.setChildren(children);
                    map.addNode(hostNode);
                }
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String freemind = map.createMap();
        System.out.println(freemind);
    }

    private static String reverse(String ip) {
        String[] split = ip.split("\\.");
        String result = split[3] + "." + split[2] + "." + split[1] + "." + split[0] + ".in-addr.arpa";
        return result;
    }
}
